package com.conorroche.taskmanagement;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
//import android.support.v4.app.NotificationCompat;

public class NotificationService extends Service {
	@Override
	public IBinder onBind(Intent intent) {
		throw new UnsupportedOperationException("Not yet implemented");
	}
	@Override
	public void onCreate(){
		super.onCreate();
	}
	public int onStartCommand(Intent intent, int flags, int startId){
		extras = intent.getExtras();
		id =(int) extras.getLong("id");
		name = extras.getString("name");
		displayNotification();
		return super.onStartCommand(intent, flags, startId);
	}
	public void displayNotification(){
		viewTask = new Intent(getApplicationContext(), ViewTaskActivity.class);
		viewTask.putExtra("name", name);
		long[] pattern = { 250, 250, 250, 250 };
		contentIntent = PendingIntent.getActivity(this, 0, viewTask, 0);
		nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
		Notification notif =  
	            new Notification.Builder(getApplicationContext())  
					.setContentTitle("There is a task you must do!")
					.setContentText(name + " has fallen due")
					.setSmallIcon(R.drawable.social_chat)
					.setContentIntent(contentIntent)
					.setOnlyAlertOnce(true)
					.setAutoCancel(true)
					.setVibrate(pattern)
					.setDefaults(-1)
					.build();
	    nm.notify(id, notif);
	}
	private Bundle extras;
	private String name;
	private int id;
	private Intent viewTask;
	private NotificationManager nm;
	private PendingIntent contentIntent;
}